import axios from 'axios';
import store from '@/store';
import { baseURL } from '@/settings';

const service = axios.create({
    baseURL: baseURL.KujoMiva,
    headers: {
        'Content-Type': 'application/json',
    },
});

// 请求拦截器
service.interceptors.request.use(
    (config) => {
        const { token } = store.getters;
        if (token) {
            config.headers.authorization = `Bearer ${token}`;
        }
        return config;
    },
    error => Promise.reject(error),
);
// 响应拦截器
service.interceptors.response.use(
    (response) => {
        const { data } = response;
        return data;
    }, error => Promise.reject(error),
);

export default service;
